﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZBJF.Warranty.Common.Common;
using ZBJF.Warranty.Model;
using ZBJF.Warranty.Model.ViewModel.BaseData;
using ZBJF.Warranty.Model.ViewModel.Product;

namespace ZBJF.Warranty.BLL
{
    public partial class D_ProvinceService
    {
        public D_Province LoadByID(int provinceId)
        {
            return LoadEntities(c => c.ProvinceID == provinceId).FirstOrDefault();
        }
        public IQueryable<D_Province> GetDProvinceAll()
        {
            return LoadEntities(o => true);
        }
        public bool IsExist(string provinceName, long provinceID = 0)
        {
            var expressionWhere = PredicateExtensions.True<D_Province>();
            if (!string.IsNullOrWhiteSpace(provinceName))
                expressionWhere = expressionWhere.And(o => o.ProvinceName.Equals(provinceName));
            if (provinceID != 0)
                expressionWhere = expressionWhere.And(o => o.ProvinceID != provinceID);
            return LoadEntities(expressionWhere).Any();
        }

        public IQueryable<D_Province> GetPagingList(D_ProvinceModel model, out int total)
        {
            var expressionWhere = PredicateExtensions.True<D_Province>();
            if (!string.IsNullOrEmpty(model.Keyword))
            {
                expressionWhere = expressionWhere.And(o => (o.ProvinceName).Contains(model.Keyword));
            }
            if (string.IsNullOrWhiteSpace(model.iSorts))
            {
                model.iSorts = "Sort asc";
            }
            return LoadPagerEntities<D_Province>(model.PageIndex, model.iDisplayLength, out total, expressionWhere, model.iSorts);
        }
    }
}
